package edu.shzu.manage.service.impl;

import edu.shzu.manage.dao.UserDao;
import edu.shzu.manage.entity.User;
import edu.shzu.manage.service.UserService;
import edu.shzu.manage.vo.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Service注解用于类上，标记当前类是一个service类，加上该注解会将当前类自动注入到spring容器中，
 * 不需要再在applicationContext.xml文件定义bean了
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;

    /**
     * 根据用户名和密码 进行登录验证
     * @param user
     * @return
     */
    @Override
    public UserRole checkUser(User user) {
        return userDao.checkUser(user);
    }

    @Override
    public User findUserById(Integer userId) {
        return userDao.findUserById(userId);
    }

    /**
     * 根据ID 查询用户
     * @param userId
     * @return
     */
    @Override
    public UserRole getUserById(Integer userId) {
        return userDao.getUserById(userId);
    }

    /**
     * 查询所有用户
     * @return
     */
    @Override
    public List<UserRole> getAllUser(Integer pageNum,Integer pageSize) {
        return userDao.getAllUser((pageNum-1)*pageSize,pageSize);
    }

    @Override
    public List<UserRole> getAllUsers() {
        return userDao.getAllUsers();
    }

    @Override
    public List<UserRole> queryByPage(String str,Integer pageNum,Integer pageSize) {
        return userDao.queryByPage(str,(pageNum-1)*pageSize,pageSize);
    }

    @Override
    public List<UserRole> query(String str) {
        return userDao.query(str);
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public int insertUserRole(Integer userId,Integer roleId) {
        return userDao.insertUserRole(userId,roleId);
    }

    /**
     * 根据ID 删除用户
     * @param userId
     * @return
     */
    @Override
    public int deleteUser(Integer userId) {
        return userDao.deleteUser(userId);
    }

    @Override
    public int deleteUserRole(Integer userId) {
        return userDao.deleteUserRole(userId);
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @Override
    public int updateUser(User user) {
        return userDao.updateUser(user);
    }
}
